devPort = 502;
devName = "test_pa"

numBits = 50000;
numInputBits = 50000;
numRegs = 50000;
numInputRegs = 50000;

debugFlag = 1;

function initDev()
	print("initDev " .. devName);
end

function simDev(func,addr,num)
	print("begin simDev " .. devName);
	
	pre=get_reg_bits(201,0,2);
	live=get_reg_bits(201,2,2);
	music=get_reg_bits(201,4,2);
	monitor=get_reg_bits(201,6,2);
	auto=get_reg_bits(201,8,2);
	priority=get_reg_bits(201,10,2);
	console=get_reg(202);
	message=get_reg(203);
	request=get_reg(204);
	
	zone="zone: ";
	for i=addr+4,addr+num-1 do
	    for j=15,0,-1 do
	        if get_reg_bit(i,j)==1 then
	            zone=zone .. j .. " ";
	        else
	            zone=zone .. "*" .. " ";
	        end
	    end
	end
	print(zone);
	
	if pre==1 then print("开始预录") end;
	if pre==2 then print("停止预录") end;
	if live==1 then print("开始实时") end;
	if live==2 then print("停止实时") end;
	if music==1 then print("开始背景音乐") end;
	if music==2 then print("停止背景音乐") end;
	if monitor==1 then print("开始监听") end;
	if monitor==2 then print("停止监听") end;
	if auto==1 then print("抑制自动广播") end;
	if auto==2 then print("使能自动广播") end;
	if priority==1 then print("普通优先级") end;
	if priority==2 then print("紧急优先级") end;
	
	print("console ID = " .. console);
	print("message ID = " .. message);
	print("request ID = " .. request);

	-- set input register (ack command)
	-- set_ireg_bit(addr, offset, value)	
	set_ireg_bit(21,0,1);

	-- reply request id ('22' hardcoded in protocol for PA)
	set_ireg(22,request);
	
	delaySim(1);
	
	-- set input register (service feedback)
	-- '4' is successful feedback indication bit
	set_ireg_bit(21,4,1);
	set_ireg(22,request);
	-- copy zone selection in orignal request
	for i=0,num-5 do
	    set_ireg(23+i,get_reg(addr+4+i))
	end
	
	delaySim(1);
	
	set_ireg(21,0);
	set_ireg(22,0);
	for i=0,num-5 do
	    set_ireg(23+i,0)
	end
	
	print("end simDev " .. devName);
end

